package com.zhentao.controller;


import com.zhentao.config.Result;
import com.zhentao.pojo.TbUser;
import com.zhentao.service.TbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/tbUser")
@RestController
public class TbUserControllerLx {


    @Autowired
    private TbUserService tbUserService;

    //登录
    @RequestMapping("login")
    public Result<TbUser> login(String username, String password){
        TbUser login = tbUserService.login(username, password);
        if (username!=null){
            return Result.success(login);
        }
        return Result.error("用户名或密码错误");
    }



    //添加用户
    @RequestMapping("addUser")
    public Result<String> addUser(TbUser tbUser){
        boolean save = tbUserService.save(tbUser);
        return save?Result.success("添加成功"):Result.error("添加失败");

    }

    //修改用户
    @RequestMapping("updateUser")
    public Result<String> updateUser(TbUser tbUser){
        boolean update = tbUserService.updateById(tbUser);
        return update?Result.success("修改成功"):Result.error("修改失败");
    }




}
